<?php

require_once 'phpmoko/externals/FlowPlayer.php';
require_once 'phpmoko/ui/Panel.php';

class Video extends Panel
{
	private $videoHTML5 = array();
	private $videoFlash = array();

	function __construct()
	{
		parent::__construct();
	}

	function addSource($video)
	{
		$splitted = explode('.', $video);

		if ($splitted[count($splitted) - 1] == "flv") {
			$this->videoFlash[] .= $video;
			FlowPlayer::activate();
		}
		else
			$this->videoHTML5[] .= $video;
	}

	function toString()
	{
		$str = '';

		if (count($this->videoHTML5) > 0) {
			$str .= '<video width="'.$this->getWidth().'" height="'.$this->getHeight().'" controls="controls" style="background-color: black">';
			foreach ($this->videoHTML5 as $value) {
				$splitted = explode('.', $value);
				$type = null;

				switch ($splitted[count($splitted) - 1]) {
					case "webm":
						$type = 'video/webm';
						break;
					case "mp4":
						$type = 'video/mp4';
						break;
					default:
						break;
				}

				$str .= '<source src="'.$value.'"'.($type != null?' type="'.$type.'"':'').'>';
			}
		}

		if (count($this->videoFlash) > 0) {
			foreach ($this->videoFlash as $value) {
				$str .= '<a href="'.$value.'" style="display:block;width:'.$this->getWidth().'px;height:'.$this->getHeight().'px;" id="player"></a>';
			}

			$str .= '<script language="JavaScript">';
			$str .= 'flowplayer("player", "'.FlowPlayer::getSWF().'");';
			$str .= '</script>';
		}

		if (count($this->videoHTML5) > 0)
			$str .= '</video>';

		return $str;
	}
}
?>